package cameratricks;

import hypermedia.video.OpenCV;

import java.awt.Dimension;

import processing.core.PApplet;
import processing.core.PImage;
import processing.video.Capture;

public class CameraRectangleizer implements Renderer {
	
	Capture capture;
	PApplet p;
	
	public CameraRectangleizer(TrickCarousel p) {
		this.capture = p.getCapture();
		this.p = p;
	}
	
	public void draw(OpenCV opencv) {
		
		Dimension size = p.getSize();
		int xdim = (int) size.getWidth();
		int ydim = (int) size.getHeight();
		
//		PImage b = capture.get();
		PImage b = opencv.image();
		
		int[] pixels = b.pixels;
		
		p.fill(150,10);
		p.rect(0,0,xdim, ydim);
		
		for (int i = 0; i < 1000; i++) {
			int x = (int) (p.random(1F) * xdim);
			int y = (int) (p.random(1F) * ydim);
			p.noStroke();
			p.fill(pixels[(int) (xdim*y + x)], 90);
			p.rect(x, y, 20 , 5);
		}
		
		for (int i = 0; i < 1000; i++) {
			int x = (int) (p.random(1F) * xdim);
			int y = (int) (p.random(1F) * ydim);
			p.noStroke();
			p.fill(pixels[(int) (xdim*y + x)], 50);
			p.rect(x, y, 5, 20);
		}
	}

}
